package logica_de_presentacion;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import logica_de_negocio.gestorPeli;

public class FormularioDirectorDePeliculaPorTitulo extends JInternalFrame
		implements ActionListener {

	private static final long serialVersionUID = 1L;
	protected JComboBox<String> director;
	protected JButton sele, cancelar;
	private String selDir;

	public FormularioDirectorDePeliculaPorTitulo(String titulo)
			throws ClassNotFoundException {

		super("Buscar de Director por titulo de Pelicula", true, true, true,
				true);
		this.setVisible(true);
		this.getContentPane().setLayout(new BorderLayout());

		JPanel pBotones = new JPanel();

		// SELECCION
		ImageIcon imagenTick = createImageIcon("/logica_de_presentacion/imagenes/TICK.gif");
		sele = new JButton("Selecionar", imagenTick);
		sele.addActionListener(this);
		pBotones.add(sele);

		// CANCELAR
		ImageIcon imagenCancelar = createImageIcon("/logica_de_presentacion/imagenes/CANCELAR.gif");
		cancelar = new JButton("Cancelar", imagenCancelar);
		cancelar.addActionListener(this);
		pBotones.add(cancelar, "South");

		// BOTONES
		this.getContentPane().add(pBotones, BorderLayout.SOUTH);
		gestorPeli gp = new gestorPeli();
		director = new JComboBox<String>(gp.getDirectores(titulo));

		this.getContentPane().add(director, BorderLayout.CENTER);
		JLabel jl = new JLabel("Indique el director de la pelicula a borrar");
		this.getContentPane().add(jl, BorderLayout.NORTH);

		this.pack();

	}

	@Override
	public void actionPerformed(ActionEvent e) {

		JButton BotonPulsado = (JButton) e.getSource();

		if (BotonPulsado == cancelar) {
			this.dispose();
		}
		if (BotonPulsado == sele) {
			selDir = (String) director.getSelectedItem();

			this.dispose();
		}
	}

	/** Returns an ImageIcon, or null if the path was invalid. */
	protected static ImageIcon createImageIcon(String path) // ICONO
	{
		java.net.URL imgURL = Button.class.getResource(path);
		if (imgURL != null) {
			return new ImageIcon(imgURL);
		} else {
			System.err.println("Couldn't find file: " + path);
			return null;
		}
	}

	public String getSelDirec() {
		return selDir;
	}
}
